package com.example.demo.testmail;/*
 *@author wujinhui
 *@create ${date} ${time} 
 *@version 1.0.0
 *@blog
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class MailTestControler {
    @Autowired
    private JavaMailSender mailSender;

    @GetMapping("/hello2")
    public String test(){
        try {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setFrom("zjut.wujinhui@qq.com");
            message.setTo("zjut.wujinhui@qq.com");
            message.setSubject("主题：简单邮件");
            message.setText("测试邮件内容");
            System.out.println("test1");
            mailSender.send(message);
        }
        catch(Exception e){
            System.out.println("异常如下--------------------");
            System.out.println(e.getMessage());
            System.out.println("异常结束");
        }
        return "index";
    }
    @GetMapping("/hello1")
    public String hello1()
    {
        return "index";
    }

}
